package diona.comet

import net.liftweb.http.{CometListener, CometActor}
import diona.model.{DropboxAuth, User}
import diona.auth.{DropboxAuthorization, DropboxAuthorizer}

/**
 * User: anton
 * Date: 26.04.11 21:36
 */
class DropboxContentManager extends CometActor with CometListener
{
  def render =
  {
    val currentToken: Option[DropboxAuth] = DropboxAuth.byUser(User.currentUser.get)
    currentToken match {
      case None => <div class="lift:embed?what=/templates-hidden/dropboxAuthRequest"/>
      case Some(token) => <div class="lift:embed?what=/templates-hidden/dropboxContent"/>
    }
  }

  protected def registerWith = DropboxAuthorizer

  override def lowPriority =
  {
    case msg: DropboxAuthorization if msg.user.id.get == User.currentUser.get.id.get => {
      reRender(false)
    }
  }
}